-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Episode 2 #15
base: master
Are you sure you want to change the base?
Episode 2 #15
Conversation
@@ -1,21 +1,46 @@ | |||
require_relative "lib/movie" | |||
require_relative "lib/api" | |||
|
|||
def get_average(movies, attribute) | |||
if attribute == "score" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cool thing in ruby --- you can tell movies what attribute you want it to collect. (collect is an alias for map, so I'm going to use map below)
data = movies.map(&:attribute)
data.inject(0.0) { |sum, rating| sum + rating } / data.size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought there would likely be a cool Ruby thing that would do this in a generic way, but I'm unfamiliar with the &:attribute notation, so I couldn't get it to work. I need to spend some time going through the Enumerable module.
Looks really good! My only suggestion is that when you are rescue'ing the find_movie method, you could be rescuing too many exceptions. I'd rather the API that does the search know that there is a condition where a movie can be not-found, and return that condition. The downside to a blank "rescue" is that it hides all exceptions that might occur, such as the website being down, or problems with your code. |
That makes sense. I had to comment out the rescue sometimes in order to figure out why the program wasn't working. |
I finished panda, tiger, and eagle.